import { App } from 'vue'

import 'element-plus/theme-chalk/el-loading.css'
import 'element-plus/theme-chalk/el-message.css'

import SSys from '~/store/SSys'
import bread from './bread/index.vue'
import sicon from './sicon/sicon.vue'
import IconDialog from './IconDialog/index.vue'

export const install = (app: App<Element>) => {
    app.component('sicon', sicon)
    app.component('bread', bread)
    app.component('IconDialog', IconDialog)
    permission(app)
}

//权限控制
const permission = (app: App<Element>) => {
    app.directive('auth', {
        mounted(el: HTMLDivElement, binding) {
            if (!SSys.auth.isPass(binding.value)) el.parentElement?.removeChild(el)
        }
    })

    //接口控制显示
    app.directive('user', {
        mounted(el, binding) {
            const api = binding.value
            const status = SSys.apiList.includes(api)
            if (!status) el.parentNode && el.parentNode.removeChild(el)
        }
    })
}

export default {
    install
}
